<?php
namespace app\index\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
class Index  extends Base{
    public function __construct(\think\App $app) {
        parent::__construct($app);
        View::assign("pagetitle",config("setting.pagetitle"));//pagetitle
        View::assign("keywords",config("setting.keywords"));//关键词
        View::assign("description",config("setting.description"));//描述
    }
    public function index()
    {
        //模板
        $template_id=Db::name("template")->where(['isdefault'=>1,'type'=>'index'])->order("sort asc")->value("template_id");
        if(!$template_id){
            $this->error("模板不存在");
        }
        return View::fetch(base_path().'data/templateFile/'.$template_id.".html");
    }

    public function message()
    {
        $data = $this->request->param();
        if (empty($data['name'])){
            $this->error('请输入您的姓名');
        }
        if (empty($data['mobile'])){
            $this->error('请输入您的联系电话');
        }
        //添加留言到数据库
        $data['addtime'] = time();
        $data['catid'] = 5;
        $result = Db::name('feedback')->save($data);
        $this->success('留言成功');
    }

    public function area()
    {
        $data = $this->request->param();
        //根据首页点击省份返回案例
        $cases = Db::name('cms_case')->where('area',$data['area'])->field('city,title,id')->select()->toArray();
        $res = area($cases,$data);
        $this->success($res);
    }
}